USE [aspnetdb]

-- =============================================
-- Author:		Lohith Ram D V
-- Create date: 
-- Description:	Tells the database to record a document is checked out.  Also checks for that right.  
--                Returns 1 if happens, 0 otherwise.
-- =============================================
CREATE PROCEDURE [sp_DocumentCheckOut] (
	@par_userid int,
	@par_docid int)
AS
BEGIN
	DECLARE @user_role int
	DECLARE @user_right int
	
	SELECT @user_role = (SELECT ([role_id])
	FROM [User1]
	WHERE @par_userid = [User1].[user1_id]);
	
	SELECT @user_right = (SELECT ([right1_id])
	FROM [Role_Right]
	WHERE @user_role=[Role_Right].[role_id]);
	
	if Exists ( Select * from Doc_Checked where doc_id=@par_docid )
	return 0;
	if(@user_right = 6)
		BEGIN
			INSERT INTO [Doc_Checked] values(@par_docid,@par_userid,1);
			RETURN 1;
		END
   ELSE
		
			return 0;
	END
